package com.yipei.business.controller;

import com.yipei.business.domain.MlServiceMessage;
import com.yipei.business.service.IMlServiceMessageService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务消息Controller
 *
 * @author yipei
 * @date 2024-12-23
 */
@RestController
@Api(tags = "服务消息", description = "服务消息管理")
@RequestMapping("/business/message")
public class MlServiceMessageController extends BaseController {
    @Autowired
    private IMlServiceMessageService mlServiceMessageService;

    /**
     * 查询服务消息列表
     */
    //@PreAuthorize("@ss.hasPermi('business:message:list')")
    @ApiOperation("服务消息获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlServiceMessage mlServiceMessage) {
        startPage();
        List<MlServiceMessage> list = mlServiceMessageService.selectMlServiceMessageList(mlServiceMessage);
        return getDataTable(list);
    }

    /**
     * 导出服务消息列表
     */
    //@PreAuthorize("@ss.hasPermi('business:message:export')")
    @ApiOperation("服务消息导出数据")
    @Log(title = "服务消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlServiceMessage mlServiceMessage) {
        List<MlServiceMessage> list = mlServiceMessageService.selectMlServiceMessageList(mlServiceMessage);
        ExcelUtil<MlServiceMessage> util = new ExcelUtil<MlServiceMessage>(MlServiceMessage.class);
        util.exportExcel(response, list, "服务消息数据");
    }

    /**
     * 获取服务消息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:message:query')")
    @ApiOperation("服务消息通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlServiceMessageService.selectMlServiceMessageById(id));
    }

    /**
     * 新增服务消息
     */
    //@PreAuthorize("@ss.hasPermi('business:message:add')")
    @ApiOperation("服务消息新增数据")
    @Log(title = "服务消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlServiceMessage mlServiceMessage) {
        return toAjax(mlServiceMessageService.insertMlServiceMessage(mlServiceMessage));
    }

    /**
     * 修改服务消息
     */
    //@PreAuthorize("@ss.hasPermi('business:message:edit')")
    @ApiOperation("服务消息修改数据")
    @Log(title = "服务消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlServiceMessage mlServiceMessage) {
        return toAjax(mlServiceMessageService.updateMlServiceMessage(mlServiceMessage));
    }

    /**
     * 删除服务消息
     */
    //@PreAuthorize("@ss.hasPermi('business:message:remove')")
    @ApiOperation("服务消息删除数据")
    @Log(title = "服务消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlServiceMessageService.deleteMlServiceMessageByIds(ids));
    }
}
